package main

import (
	"bishow/api"
	"log"
	"net/http"

	"github.com/gorilla/mux"
	// "bishow/config"
	// "bishow/server"

	"bishow/modbus"
)

var modbusServer *modbus.ModbusServer

func main() {
	// cfg := config.LoadConfig()

	// s, err := server.NewServer(cfg)
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// log.Printf("Starting server on port %d", cfg.ServerPort)
	// if err := s.Start(); err != nil {
	// 	log.Fatalf("Error starting server: %v", err)
	// }

	r := mux.NewRouter()

	// API routes
	apiRouter := r.PathPrefix("/api").Subrouter()
	// apiRouter.Use(auth.AuthMiddleware)
	apiRouter.HandleFunc("/start", api.StartModbusServer).Methods("POST")
	apiRouter.HandleFunc("/stop", api.StopModbusServer).Methods("POST")
	apiRouter.HandleFunc("/create", api.CreateModbusServer).Methods("POST")
	apiRouter.HandleFunc("/pause", api.PauseModbusServer).Methods("POST")
	apiRouter.HandleFunc("/resume", api.ResumeModbusServer).Methods("POST")
	apiRouter.HandleFunc("/data", api.GetModbusData).Methods("GET")

	// Serve static files and HTML template
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
	r.HandleFunc("/", api.ServeHTML)

	log.Fatal(http.ListenAndServe(":38080", r))
}
